<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>美容师</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link type="text/css" rel="stylesheet" media="screen" href="__FONT__/css/style.css"/>
    <link type="text/css" rel="stylesheet" media="screen" href="__FONT__/css/media.css"/>
</head>
<body style="background:#f7f7f9;">
	<include file="Public/customHeaderNoBack" title="美容师"/>
    <header class="beautylist_head">
      <div class="btylisthead">
       <i><img src="__FONT__/images/loction.png" ></i>
       <h1><a href="{:U('/Index/customAddress/type/beautician')}">{$address}</a></h1>
      </div>
    </header>
 	<section class="beautylist_sec meirongshi">
		<div>
			<ul></ul>
       	</div>
	</section>
	<div class="load">
       <div class="load_main">
          <img src="__FONT__/images/loading.gif">
          <p>正在加载...</p>
       </div>
    </div>
    <include file="Public/footer" />
    
    <script src="__FONT__/js/zepto.min.js"></script>
    <script type="text/javascript" src="__FONT__/js/zepto.cookie.js"></script>
    <script type="text/javascript" src="__FONT__/js/mustache.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
    <include file="Public/share-js" />
    <script>
    var beauticianTemp = '<li data-id="{{id}}">'
				       	+'<a href="{:U(\'Index/detail\')}?id={{id}}">'
				    	+'<div class="btylistmain womenmain">'
				    	+'<h2>'
				    	+'{{#hasProfile}}'
				           	+'<img src="__UPLOADS__/Profile/{{profile_img}}">'
				        	+'{{/hasProfile}}{{^hasProfile}}'
				        	+'<img src="__FONT__/images/defaultProfile.png">'
				        	+'{{/hasProfile}}'
				        	+'</h2>'
				        	+'<dd>'
				        	+'<h3><span>{{name}}</span></h3>'
				        	+'<h3>{{{startHtml}}}</h3>'
				        	+'<h3><strong>服务次数：<b>{{service_total}}</b></strong><strong>评论：<b>{{comment_total}}</b></strong></h3>'
				        	+'</dd>'
				        	+'</div>'
				        	+'</a>'
				        	+'</li>';
    
   	$(function () {
    	$(".btylisthead").find('i').click(function () {
    		$(this).find('img').addClass('load_rotate');
    		getLocationByWeixin();
    	});
    });
    
  //显示地址信息窗口
    function showLocationInfo(pt, rs){
    	var addComp = rs.addressComponents;
        if (typeof startGetLocation == 'undefined') {
            $(".btylisthead").find('h1 a').text(addComp.district + addComp.street + addComp.streetNumber);
        }
        
        $(".btylisthead").find('i img').removeClass('load_rotate');
        
        var selectProvince = localStorage.getItem('select_province'),
        	selectCity = localStorage.getItem('select_city'),
        	ajaxLoadParams = {},
        	currentProvince = addComp.province,
        	currentCity = addComp.city;
        
        if ($.trim(selectProvince) != '' && $.trim(selectCity) != '' && 
        		(currentProvince != selectProvince || currentCity != selectCity)) {
        	ajaxLoadParams ['province'] = selectProvince;
        	ajaxLoadParams ['city'] = selectCity;
        	
        	$('.beautylist_head').find('h1 a').text('定位于所选城市不符合，请手动输入');
        } else {
        	ajaxLoadParams ['lat'] = pt.lat;
        	ajaxLoadParams ['lng'] = pt.lng;
        	ajaxLoadParams ['province'] = addComp.province;
        	ajaxLoadParams ['city'] = addComp.city;
        	
        	var currentTime = new Date().getTime();
			var $expires = currentTime + 7 * 24 * 3600 * 1000;
        	$.cookie('lat', pt.lat, $expires);
			$.cookie('lng', pt.lng, $expires);
        }
       	
    	loadBeauticain(ajaxLoadParams);
    }
  
  	function loadBeauticain(requestParams) {
  		$.ajax({
  			url: '{:U("/Index/ajaxLoadBeautician")}',
  			data: requestParams,
  			dataType: 'json',
  			success: function (result) {
  				if (result.status == 1) {
  					var data = result.data;
  					
  					if (!$.isEmptyObject(data)) {
	  					var html = '';
	  					for (var i in data) {
	  						var beautician = data [i];
	  						var startHtml = '';
	  						var start = parseInt(beautician.start);
	  						for (var j = 0 ; j < 5; j++) {
	  							if (start > j) {
	  								startHtml += '<i></i>';
	  							}
	  						}
	  						beautician.startHtml = startHtml;
	  						beautician.hasProfile = beautician.profile_img?true:false;
	  						
	  						html += Mustache.render(beauticianTemp, beautician);
	  					}
  					} else {
  						html = '<div class="no_bank"><h1>美滴滴</h1><p>没有可选美容师~</p></div>';
  					}
  					$('.beautylist_sec ul').empty().append(html);
  					
  					closeLoading();
  				}
  			},
  			error: function (e, t, s) {
  				closeLoading();
  			}
  		});
  	}
  	 
  	function closeLoading() {
  		$('.load').hide();
  	}
  	function openLoading() {
  		$('.load').show();
  	}
    </script>
    <if condition="$address">
    <script>
    	startGetLocation = false;
    	var gc = new BMap.Geocoder();
    	localStorage.setItem('location', '{$latitude},{$longitude}');
        var point = new BMap.Point('{$longitude}', '{$latitude}'); //初始化地图中心点
        gc.getLocation(point, function(rs){
            showLocationInfo(point, rs);
        });
    </script>
    </if>
</body>
</html>